import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyClassLoader extends ClassLoader {

    public static void main(String[] args) {
        try {
            Class helloClass = new MyClassLoader().findClass("Hello");
            Method helloMethod = helloClass.getDeclaredMethod("hello");
            helloMethod.invoke(helloClass.newInstance());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }

    public Class<?> findClass(String name) {
        byte res[] = new byte[0];
        try {
            res = loadClassFile("src/main/java/Hello.xlass");
            for (int i = 0; i < res.length; i++) {
                res[i] = (byte) (255 - res[i]);
            }
            return defineClass(name, res, 0, res.length);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public byte[] loadClassFile(String path) throws IOException {
        FileInputStream fin = new FileInputStream(path);
        byte b[] = new byte[1024];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len = 0;
        while ((len = fin.read(b)) != -1) {
            out.write(b, 0, len);
        }
        fin.close();
        out.close();
        byte res[] = out.toByteArray();
        return res;
    }

}
